<template>
  <el-dialog
    title="客户群设置"
    :visible.sync="$attrs.visable"
    width="600px"
    :before-close="handleClose"
    append-to-body
  >
    <el-form
      ref="ruleForm"
      :model="form"
      size="small"
      label-width="100px"
      label-position="top"
    >
      <el-form-item label="新群设置" prop="checkList">
        <div class="bg_f5 formbg">
          <el-checkbox-group v-model="form.checkList" class="flexcolumn">
            <el-checkbox :label="1">新建群自动开启群聊邀请确认</el-checkbox>
            <el-checkbox :label="2">新建群自动禁止群成员改群名</el-checkbox>
            <el-checkbox :label="3">新群自动保存至通讯录</el-checkbox>
          </el-checkbox-group>
        </div>
      </el-form-item>
      <el-form-item label="群操作设置" prop="checkList">
        <div class="bg_f5 formbg">
          <div v-for="(item,index) in optionsList" :key="index" class="flex mb-10">
            <div class="f_title">{{item.label}}</div>
            <div class="f_content flex">
              <el-input v-model="item.min" placeholder="" style="width:78px" class="mr-5" @blur="onBlur(item,'min')"></el-input> 秒
              <span class="divi"> - </span>
              <el-input v-model="item.max" placeholder="" style="width:78px" class="mr-5" @blur="onBlur(item,'max')"></el-input> 秒
              <span class="c_primary commhover pl-10" @click="handleDefault(item)">设为推荐值</span>
            </div>
          </div>
        </div>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleClose">取 消</el-button>
      <el-button size="small" type="primary" @click="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      form: {
        checkList: [],
        receive: "",
      },
      // rules: {
      //   rollout: [
      //     { required: true, message: "请选择转出企微号", trigger: "change" },
      //   ],
      //   receive: [
      //     { required: true, message: "请选择接收企微号", trigger: "change" },
      //   ],
      // },
      optionsList: [
        { label: "转让群主间隔：", min: 5, max:10 },
        { label: "修改群名称间隔：", min: 5, max:10 },
        { label: "批量退群间隔：", min: 5, max:10 },
        { label: "群聊邀请确认间隔：", min: 5, max:10 },
      ],
      options: [],
    };
  },
  props: {
    type: {
      default: "", // 1 转让群主  2 设置群管
    },
  },
  created() {
    console.log("type:", this.type);
  },
  methods: {
    handleClose() {
      this.$emit("update:visable", false);
    },

    onBlur(item, type){
      // 使用正则表达式匹配正整数
      const regex = /^[1-9]\d*$/;
      // 如果输入的值不是正整数，则将其设置为上一个有效值
      if (!regex.test(item[type])) {
        if(type=='min'){
          item.min = 5
        }else{
          item.max = 10
        }
      }else{
        if(item[type]>999){
          item[type] = 999
        }
      }
    },

    handleDefault(item){
      item.min = 5
      item.max = 10
    },

    handleSubmit() {},
  },
};
</script>
<style lang="scss" scoped>
.checkbox {
  padding: 2px 16px;
  border-radius: 2px;
  border: 1px solid #f0f0f0;
}
.formbg{
  padding: 12px 16px;
}
.f_title{
  width: 140px;
}
.f_content{
  width: calc(100% - 140px);
}
.divi{
  display: inline-block;
  margin: 0 6px;
}
.el-form{
  ::v-deep .el-form-item__label{
    padding-bottom: 5px!important;
  }
}

</style>